package first.niuke.huawei.mediumDifficulty;

import java.util.Scanner;

/**
 * @ClassName HJ99
 * @description:
 * @author: 荣燊
 * @create: 2021-07-08 12:58
 **/
public class HJ99 {
    // 自守数

    // 尾数为0 1 5 6的才可能是自守数
    // 再通过字符串匹配
    public static void main(String[] args) {
        Scanner scaner = new Scanner(System.in);
        while (scaner.hasNext()) {
            int n = scaner.nextInt();
            System.out.println(CalcAutomorphicNumbers(n));
        }
    }

    public static int CalcAutomorphicNumbers (int n) {
        int sum = 0;
        for (int i=0; i<=n; i++) {
            if (i % 10 == 0 || i % 10 == 1 || i % 10 == 5 || i % 10 == 6) {
                String s1 = toString1(i*i);
                String s2 = toString1(i);
                if (s1.substring(0, s2.length()).equals(s2)) {
                    sum++;
                }
            }
        }
        return sum;
    }

    public static String toString1(long a) {
        StringBuilder str = new StringBuilder();
        while (a != 0) {
            str.append(a%10);
            a /= 10;
        }
        return str.toString();
    }
}
